﻿using UnityEngine;

namespace Assets.Scripts.DL.Enemy.CommonEnemy.States.CommonState {
	public class Idle : CommonState<Controller> {
		float _idleTime;
		Timer _timer;
		bool _isIdleOver;

		public Idle(Controller controller, StateEnum stateName) : base(controller, stateName) {
			AddConditionToSelf(() => false);
			AddNewTransition(StateEnum.Move, () => _isIdleOver);
			_timer = new Timer();
		}

		public override void Enter() {
			//Debug.Log("Idle  in");
			if (_controller.IsTouchingWall() || !_controller.IsOnGround())
				_controller.ChangeFaceDir();
			_controller.PlayAnim(StateEnum.Idle);
			_controller.Velocity = Vector2.zero;
			var range = _controller.Config.IdleTimeRange;
			_idleTime = Random.Range(range.x, range.y);
			_timer.Reset();
			_isIdleOver = false;
		}
		public override void Update() {
			if (_timer.Elapsed > _idleTime) {
				_isIdleOver = true;
			}
		}

		public override void Exit() {
			//Debug.Log("Idle out");

		}
	}
}
